package com.sq.partner.manager.service.impl;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.dao.FacadePrintConfDao;
import com.sq.partner.manager.dao.INlifeConDao;
import com.sq.partner.manager.dao.INlifeCovDao;
import com.sq.partner.manager.dao.INlifePlanDao;
import com.sq.partner.manager.dao.INlifeProdDao;
import com.sq.partner.manager.dao.INlifeRiskDao;
import com.sq.partner.manager.dao.ITradFeeAdjustConditionDao;
import com.sq.partner.manager.dao.NlifeRationDao;
import com.sq.partner.manager.dao.TradProdPropDao;
import com.sq.partner.manager.mybatis.model.NlifeCon;
import com.sq.partner.manager.mybatis.model.NlifeCoreProd;
import com.sq.partner.manager.mybatis.model.NlifeCoreProdRisk;
import com.sq.partner.manager.mybatis.model.NlifeCov;
import com.sq.partner.manager.mybatis.model.NlifePlan;
import com.sq.partner.manager.mybatis.model.NlifeProd;
import com.sq.partner.manager.mybatis.model.NlifeRation;
import com.sq.partner.manager.mybatis.model.NlifeRisk;
import com.sq.partner.manager.mybatis.model.TradFeeAdjustCondition;
import com.sq.partner.manager.mybatis.model.TradProdInst;
import com.sq.partner.manager.mybatis.model.TradProdProp;
import com.sq.partner.manager.service.IGatewayChannelInfoConfigService;
import com.sq.partner.manager.service.INlifeProdConfigService;
import com.sq.partner.manager.service.TradProdPropService;
import com.sq.partner.manager.util.JsonUtils;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.StrUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.springframework.ui.ModelMap;

@Service
public class NlifeProdConfigServiceImpl implements INlifeProdConfigService {

	@Resource
	private IGatewayChannelInfoConfigService gatewayChannelInfoConfigService;
	
	@Resource
	private INlifePlanDao nlifePlanDao;
	
	@Resource
	private INlifeProdDao nlifeProdDao;
	@Resource
	private TradProdPropDao tradProdPropDao;
	@Resource
	private FacadePrintConfDao facadePrintConfDao;
	@Resource
	ITradFeeAdjustConditionDao tradFeeAdjustConditionDao;
	
	@Resource
	private INlifeRiskDao nlifeRiskDao;
	
	@Resource
	private INlifeConDao nlifeConDao;
	
	@Resource
	private INlifeCovDao nlifeCovDao;
	@Resource
	private TradProdPropService tradProdPropService;

	@Resource
	private NlifeRationDao nlifeRationDao;
	
	@Override
	public Page<NlifeProd> queryProdPageByCriteria(Page<NlifeProd> page) throws Exception {
		return nlifeProdDao.queryProdPageByCriteria(page);
	}
	
	@Override
	public NlifeProd saveProd(NlifeProd prod) throws Exception {
		String currMaxProdCode = nlifeProdDao.findMaxNewLifeTradProdCode(prod.getCoreProdCode());
		String nextProdCodeVal="";
		if(StrUtil.isNotEmpty(currMaxProdCode)){
			long tradProdCode= Long.parseLong(currMaxProdCode.substring(6))+1;
			nextProdCodeVal=String.valueOf(tradProdCode);
			for (int i = 0; i < 5-String.valueOf(tradProdCode).length(); i++) {
				nextProdCodeVal="0"+nextProdCodeVal;
			}
			nextProdCodeVal =currMaxProdCode.substring(0,6)+nextProdCodeVal;	
			prod.setProdCode(nextProdCodeVal);

		}else{
			prod.setProdCode("PN"+prod.getCoreProdCode()+"00001");
		}
			if(prod.getRation()!=null && prod.getRation().length()>0 && "Y".equals(prod.getIsRation())){
				JsonObject o = new JsonParser().parse(prod.getRation()).getAsJsonObject();
				JsonArray jary = o.get("rationList").getAsJsonArray();
				NlifeRation nlifeRation = null;
					for (JsonElement jsonElement : jary) {
						String rationId =jsonElement.getAsJsonObject().get("rationid").getAsString();
						String rationName=jsonElement.getAsJsonObject().get("rationname").getAsString();
						String jobLevel=jsonElement.getAsJsonObject().get("jobLevel").getAsString();
						if(StrUtil.isNotEmpty(rationId) && StrUtil.isNotEmpty(rationName)){
							nlifeRation = new NlifeRation();
							nlifeRation.setRationId(rationId);
							nlifeRation.setRationName(rationName);
							nlifeRation.setProdCode(prod.getProdCode());
							nlifeRation.setJobLevel(jobLevel);
							nlifeRationDao.addRation(nlifeRation);
							
						}
					}
				}else{
					NlifeRation	nlifeRation = new NlifeRation();
					nlifeRation.setRationId("1");
					nlifeRation.setRationName("保障计划1");
					nlifeRation.setProdCode(prod.getProdCode());
					nlifeRationDao.addRation(nlifeRation);
				}
		nlifeProdDao.saveProd(prod);//保存产品
		/**电子保单模板处理*/
		/**是否新增电子保单模板*/
		if(StrUtil.isNotEmpty(prod.getEpolicyCode())){
			/**模板代码非空，新增电子保单模板*/
			TradProdProp prodProp=new TradProdProp();
			prodProp.setProdValue(prod.getEpolicyCode());
			prodProp.setePolicyTitle(prod.getEpolicyTitle());
			prodProp.setTradProdCod(prod.getProdCode());
			tradProdPropService.addProdProp(prodProp);
		}
		if(prod.getAdjustStr()!=null && prod.getAdjustStr().length()>0){
			JsonObject o = new JsonParser().parse(prod.getAdjustStr()).getAsJsonObject();
			String adjustId= o.get("adjustId").getAsString();
			JsonArray jary = o.get("adjustList").getAsJsonArray();
			TradFeeAdjustCondition tradFeeAdjustCondition = null;
			if(StrUtil.isNotEmpty(adjustId)){
				for (JsonElement jsonElement : jary) {
					String peoplenum =jsonElement.getAsJsonObject().get("peoplenum").getAsString();
					String coefficient=jsonElement.getAsJsonObject().get("coefficient").getAsString();
					if(StrUtil.isNotEmpty(peoplenum) && StrUtil.isNotEmpty(coefficient)){
						BigDecimal premRate = BigDecimal.valueOf(Double.parseDouble(coefficient)/100);
						tradFeeAdjustCondition = new TradFeeAdjustCondition();
						tradFeeAdjustCondition.setAdjustId(adjustId);
						tradFeeAdjustCondition.setTradProdCode(prod.getProdCode());
						tradFeeAdjustCondition.setPremRate(premRate.setScale(2, BigDecimal.ROUND_HALF_UP));
						tradFeeAdjustCondition.setCond1(Long.parseLong(peoplenum));
						tradFeeAdjustConditionDao.saveTradFeeAdjustCondition(tradFeeAdjustCondition);
					}
				}
			}
		}
		return prod;
	}

	@Override
	public NlifeProd copyAddProd(NlifeProd prod) throws Exception {
		String currMaxProdCode = nlifeProdDao.findMaxNewLifeTradProdCode(prod.getCoreProdCode());
		String nextProdCodeVal="";
		if(StrUtil.isNotEmpty(currMaxProdCode)){
			long tradProdCode= Long.parseLong(currMaxProdCode.substring(6))+1;
			nextProdCodeVal=String.valueOf(tradProdCode);
			for (int i = 0; i < 5-String.valueOf(tradProdCode).length(); i++) {
				nextProdCodeVal="0"+nextProdCodeVal;
			}
			nextProdCodeVal =currMaxProdCode.substring(0,6)+nextProdCodeVal;
			prod.setProdCode(nextProdCodeVal);

		}else{
			prod.setProdCode("PN"+prod.getCoreProdCode()+"00001");
		}
		nlifeProdDao.saveProd(prod);//保存产品
		/**电子保单模板处理*/
		/**是否新增电子保单模板*/
		if(StrUtil.isNotEmpty(prod.getEpolicyCode())){
			/**模板代码非空，新增电子保单模板*/
			TradProdProp prodProp=new TradProdProp();
			prodProp.setProdValue(prod.getEpolicyCode());
			prodProp.setePolicyTitle(prod.getEpolicyTitle());
			prodProp.setTradProdCod(prod.getProdCode());
			tradProdPropService.addProdProp(prodProp);
		}
		if(prod.getAdjustStr()!=null && prod.getAdjustStr().length()>0){
			JsonObject o = new JsonParser().parse(prod.getAdjustStr()).getAsJsonObject();
			String adjustId= o.get("adjustId").getAsString();
			JsonArray jary = o.get("adjustList").getAsJsonArray();
			TradFeeAdjustCondition tradFeeAdjustCondition = null;
			if(StrUtil.isNotEmpty(adjustId)){
				for (JsonElement jsonElement : jary) {
					String peoplenum =jsonElement.getAsJsonObject().get("peoplenum").getAsString();
					String coefficient=jsonElement.getAsJsonObject().get("coefficient").getAsString();
					if(StrUtil.isNotEmpty(peoplenum) && StrUtil.isNotEmpty(coefficient)){
						BigDecimal premRate = BigDecimal.valueOf(Double.parseDouble(coefficient)/100);
						tradFeeAdjustCondition = new TradFeeAdjustCondition();
						tradFeeAdjustCondition.setAdjustId(adjustId);
						tradFeeAdjustCondition.setTradProdCode(prod.getProdCode());
						tradFeeAdjustCondition.setPremRate(premRate.setScale(2, BigDecimal.ROUND_HALF_UP));
						tradFeeAdjustCondition.setCond1(Long.parseLong(peoplenum));
						tradFeeAdjustConditionDao.saveTradFeeAdjustCondition(tradFeeAdjustCondition);
					}
				}
			}
		}
		return prod;
	}

	@Override
	public NlifeProd updateProd(NlifeProd prod) throws Exception {
		nlifeProdDao.updateProd(prod);
		/**保单模板处理*/
		if(StrUtil.isEmpty(prod.getEpolicyCode())){
			/**删除电子保单模板信息**/
			tradProdPropDao.deleteProdProp(prod.getProdCode());
		}else{
			TradProdProp prodProp=new TradProdProp();
			prodProp.setProdValue(prod.getEpolicyCode());
			prodProp.setePolicyTitle(prod.getEpolicyTitle());
			prodProp.setTradProdCod(prod.getProdCode());
			/**执行更新更新条数小于等于0，执行新增**/
			if(tradProdPropDao.updateProdProp(prodProp)<=0){
				tradProdPropDao.addProdProp(prodProp);
			}
		}
		TradProdInst queryTem = new TradProdInst();
		queryTem.setTradProdCode(prod.getProdCode());
		tradFeeAdjustConditionDao.deleteTradFeeAdjustConditionsByTradProdCode(queryTem);//删除折扣系数关联表信息
		if(StrUtil.isNotEmpty(prod.getAdjustStr())){
			JsonObject o = new JsonParser().parse(prod.getAdjustStr()).getAsJsonObject();
			String adjustId= o.get("adjustId").getAsString();
			JsonArray jary = o.get("adjustList").getAsJsonArray();
			TradFeeAdjustCondition tradFeeAdjustCondition = null;
			if(StrUtil.isNotEmpty(adjustId)){
				for (JsonElement jsonElement : jary) {
					String peoplenum =jsonElement.getAsJsonObject().get("peoplenum").getAsString();
					String coefficient=jsonElement.getAsJsonObject().get("coefficient").getAsString();
					if(!StrUtil.isEmpty(peoplenum)&&!StrUtil.isEmpty(coefficient)){
						tradFeeAdjustCondition = new TradFeeAdjustCondition();
						tradFeeAdjustCondition.setTradProdCode(prod.getProdCode());
						tradFeeAdjustCondition.setAdjustId(adjustId);
						BigDecimal premRate = BigDecimal.valueOf(Double.parseDouble(coefficient)/100);
						tradFeeAdjustCondition.setCond1(Long.parseLong(peoplenum));
						tradFeeAdjustCondition.setPremRate(premRate.setScale(2, BigDecimal.ROUND_HALF_UP));
						tradFeeAdjustConditionDao.saveTradFeeAdjustCondition(tradFeeAdjustCondition);
					}
					
				}
			}
		}
/*		if(prod.getRation()!=null && prod.getRation().length()>0 && "Y".equals(prod.getIsRation())){
			nlifeRationDao.deleteRationByProdCode(prod.getProdCode());
			JsonObject o = new JsonParser().parse(prod.getRation()).getAsJsonObject();
			JsonArray jary = o.get("rationList").getAsJsonArray();
			NlifeRation nlifeRation = null;
				for (JsonElement jsonElement : jary) {
					String rationId =jsonElement.getAsJsonObject().get("rationid").getAsString();
					String rationName=jsonElement.getAsJsonObject().get("rationname").getAsString();
					String jobLevel=jsonElement.getAsJsonObject().get("jobLevel").getAsString();
					if(StrUtil.isNotEmpty(rationId) && StrUtil.isNotEmpty(rationName)){
						nlifeRation = new NlifeRation();
						nlifeRation.setRationId(rationId);
						nlifeRation.setRationName(rationName);
						nlifeRation.setProdCode(prod.getProdCode());
						nlifeRation.setJobLevel(jobLevel);
						nlifeRationDao.addRation(nlifeRation);
						
					}
				}
			}else{
				nlifeRationDao.deleteRationByProdCode(prod.getProdCode());
				NlifeRation	nlifeRation = new NlifeRation();
				nlifeRation.setRationId("1");
				nlifeRation.setRationName("保障计划1");
				nlifeRation.setProdCode(prod.getProdCode());
				nlifeRationDao.addRation(nlifeRation);
			}*/
		//编辑产品时判断产品是否有方案，如果有就清除缓存
		List<NlifePlan> tradInsuPlanLists = nlifePlanDao.queryPartnerInfoByProdCode(prod.getProdCode());
		if(null!= tradInsuPlanLists && tradInsuPlanLists.size()>0){
			gatewayChannelInfoConfigService.clearAllNewLifeCacheByChannelCodeExtend(tradInsuPlanLists);
		}
		return prod;
	}

	@Override
	public boolean deleteProd(String prodCode) throws Exception {
		return nlifeProdDao.deleteProd(prodCode);
	}

	@Override
	public Page<NlifeRisk> queryRiskPageByCriteria(Page<NlifeRisk> page,String prodCode) throws Exception {
		return nlifeRiskDao.queryRiskPageByCriteria(page, prodCode);
	}

	@Override
	public boolean saveRisk(NlifeRisk risk) throws Exception {
		boolean b = nlifeRiskDao.saveRisk(risk);
		if(b){
			List<NlifePlan> tradInsuPlanLists = nlifePlanDao.queryPartnerInfoByProdCode(risk.getProdCode());
			if(null!= tradInsuPlanLists && tradInsuPlanLists.size()>0){
				gatewayChannelInfoConfigService.clearAllNewLifeCacheByChannelCodeExtend(tradInsuPlanLists);
			}
		}
		return b; 
	}

	@Override
	public boolean updateRisk(NlifeRisk risk) throws Exception {
		boolean b = nlifeRiskDao.updateRisk(risk);
		if(b){
			List<NlifePlan> tradInsuPlanLists = nlifePlanDao.queryPartnerInfoByProdCode(risk.getProdCode());
			if(null!= tradInsuPlanLists && tradInsuPlanLists.size()>0){
				gatewayChannelInfoConfigService.clearAllNewLifeCacheByChannelCodeExtend(tradInsuPlanLists);
			}
		}
		return b;
	}

	@Override
	public boolean deleteRisk(NlifeRisk risk) throws Exception {
		boolean b = nlifeRiskDao.deleteRisk(risk);
		if(b){
			List<NlifePlan> tradInsuPlanLists = nlifePlanDao.queryPartnerInfoByProdCode(risk.getProdCode());
			if(null!= tradInsuPlanLists && tradInsuPlanLists.size()>0){
				gatewayChannelInfoConfigService.clearAllNewLifeCacheByChannelCodeExtend(tradInsuPlanLists);
			}
		}
		return b;
	}

	@Override
	public Page<NlifeCov> queryCovPageByCriteria(Page<NlifeCov> page) throws Exception {
		return nlifeCovDao.queryCovPageByCriteria(page);
	}

	@Override
	public boolean saveCov(NlifeCov cov) throws Exception {
		boolean b = nlifeCovDao.saveCovInfo(cov);
		if(b){
			List<NlifePlan> tradInsuPlanLists = nlifePlanDao.queryPartnerInfoByProdCode(cov.getProdCode());
			if(null!= tradInsuPlanLists && tradInsuPlanLists.size()>0){
				gatewayChannelInfoConfigService.clearAllNewLifeCacheByChannelCodeExtend(tradInsuPlanLists);
			}
		}
		return b;
	}

	@Override
	public boolean deleteCov(NlifeCov cov) throws Exception {
		boolean b = nlifeCovDao.deleteCov(cov);
		if(b){
			List<NlifePlan> tradInsuPlanLists = nlifePlanDao.queryPartnerInfoByProdCode(cov.getProdCode());
			if(null!= tradInsuPlanLists && tradInsuPlanLists.size()>0){
				gatewayChannelInfoConfigService.clearAllNewLifeCacheByChannelCodeExtend(tradInsuPlanLists);
			}
		}
		return b;
	}

	@Override
	public Page<NlifeCon> queryConPageByCriteria(Page<NlifeCon> page,String prodCode)
			throws Exception {
		return nlifeConDao.queryProdConInsureInfoPage(page, prodCode);
	}

	@Override
	public Page<NlifeCoreProd> queryNLifeCoreProd(Page<NlifeCoreProd> page) throws Exception {
		return nlifeProdDao.queryNLifeCoreProd(page);
	}

	@Override
	public NlifeProd queryProdInfoById(String param) throws Exception {
		NlifeProd reObj = nlifeProdDao.queryProdInfoById(param);
		TradProdInst queryTem = new TradProdInst();
		queryTem.setTradProdCode(reObj.getProdCode());
		List<TradFeeAdjustCondition> tradFeeAdjustConditions = tradFeeAdjustConditionDao.queryTradFeeAdjustConditionsByTradProdCode(queryTem);
		String adjustStr = "";
		if(tradFeeAdjustConditions!=null&&!tradFeeAdjustConditions.isEmpty()){
			String adjustId = tradFeeAdjustConditions.get(0).getAdjustId();
			JsonObject jo = new JsonObject();
			jo.addProperty("adjustId", adjustId);
			JsonParser jp=new JsonParser();
			JsonElement je =jp.parse(JsonUtils.toJson(tradFeeAdjustConditions));
			jo.add("adjustList", je);
			adjustStr=JsonUtils.toJson(jo);
		}
		reObj.setAdjustStr(adjustStr);
		return reObj;
	}

	@Override
	public boolean queryPrimaryRiskIsExist(String prodCode) throws Exception {
		return nlifeCovDao.queryPrimaryRiskIsExist(prodCode);
	}

	@Override
	public Page<NlifeCoreProdRisk> queryCoreProdRiskTempletPageById(Page<NlifeCoreProdRisk> page, String coreProdCode,String prodCode, String riskCode, String riskName) throws Exception {
		return nlifeRiskDao.queryCoreProdRiskTempletPageById(page, coreProdCode,prodCode, riskCode, riskName);
	}

	@Override
	public List<NlifeProd> queryAllCoreProdInfoList() throws Exception {
		return nlifeProdDao.queryAllCoreProdInfoList();
	}

	@Override
	public boolean deleteRiskInfoByProdCode(String prodCode) throws Exception {
		return nlifeRiskDao.deleteRiskInfoByProdCode(prodCode);
	}

	@Override
	public boolean deleteCovInfoByProdCode(String prodCode) throws Exception {
		return nlifeCovDao.deleteCovInfoByProdCode(prodCode);
	}

	@Override
	public boolean saveProdConInsure(NlifeCon nc) throws Exception {
		return nlifeConDao.saveProdConInsure(nc);
	}

	@Override
	public boolean deleteProdConInsureByProdCode(String prodCode) throws Exception {
		return nlifeConDao.deleteProdConInsureByProdCode(prodCode);
	}

	@Override
	public boolean searchProdConInsureInfoByProdCode(String prodCode) throws Exception {
		return nlifeConDao.searchProdConInsureInfoByProdCode(prodCode);
	}

	@Override
	public boolean isExistLinkPlanByProdCode(String prodCode) throws Exception {
		List<NlifePlan> ls = nlifePlanDao.queryPartnerInfoByProdCode(prodCode);
		if(null!=ls&&ls.size()>0){
			return true;
		}
		return false;
	}

	@Override
	public List<NlifeCov> queryItemsAndCovsInfoByPolicyId(String policyId) throws Exception {
		return nlifeCovDao.queryItemsAndCovsInfoByPolicyId(policyId);
	}

	@Override
	public boolean queryIsExistRiskPrimaryKeyByParams(NlifeRisk risk) throws Exception {
		return nlifeRiskDao.queryIsExistRiskPrimaryKeyByParams(risk);
	}

	@Override
	public Page<NlifeCov> queryCovPageByCriteria1(Page<NlifeCov> page)
			throws Exception {
		// TODO Auto-generated method stub
		return nlifeCovDao.queryCovPageByCriteria1(page);
	}

	@Override
	public boolean updateMRisk(String prodCode, String tradRiskCode,
			Integer flag,String rationId) throws Exception {

		return nlifeRiskDao.updateMRisk(prodCode, tradRiskCode, flag,rationId);
	}

	@Override
	public boolean updateSaleCode(Map<String, String> map) throws Exception {
		// TODO Auto-generated method stub
		return nlifeProdDao.updateSaleCode(map);
	}

	@Override
	public boolean queryPrimaryRiskIsExist1(String prodCode) throws Exception {
		// TODO Auto-generated method stub
		return nlifeCovDao.queryPrimaryRiskIsExist1(prodCode);
	}

	@Override
	public Integer queryRiskType(Map<String, String> map) throws SQLException {
		return nlifeRiskDao.queryRiskType(map);
	}

	@Override
	public boolean queryPrimaryRiskIsExist2(Map<String, String> map)
			throws Exception {
		// TODO Auto-generated method stub
		return nlifeCovDao.queryPrimaryRiskIsExist2(map);
	}

	@Override
	public boolean updateRiskMain(Map<String, String> map) throws Exception {
		// TODO Auto-generated method stub
		return nlifeProdDao.updateRiskMain(map);
	}

	@Override
	public Integer queryPrimaryRiskIsExist3(String prodCode) throws Exception {
	
		return nlifeCovDao.queryPrimaryRiskIsExist3(prodCode);
	}

	@Override
	public List<Map<String, Object>> impNlifeProd(Map<String, Object>map) throws Exception {
		
		return nlifeProdDao.impNlifeProd(map);
	}

	@Override
	public List<Map<String, Object>> impNlifeRisk(Map<String, Object>map)
			throws SQLException {
		return nlifeRiskDao.impNlifeRisk(map);
	}

	@Override
	public List<Map<String, Object>> impNlifeCov(Map<String, Object> map)
			throws SQLException {
		return nlifeCovDao.impNlifeCov(map);
	}

	@Override
	public  List<Map<String, Object>> impNlifeProp(Map<String, Object> map)
			throws SQLException {
		return tradProdPropDao.impNlifeProp(map);
	}
	@Override
	public List<Map<String, Object>> impNocarProp(Map<String, Object> map)
			throws SQLException {
		return tradProdPropDao.impNocarProp(map);
	}
	@Override
	public  List<Map<String, Object>> impNlifePrint(Map<String, Object> map)
			throws SQLException {
		return facadePrintConfDao.impNlifePrint(map);
	}

	@Override
	public List<NlifeRation> queryRiskAndRationByParam(Map<String, Object> map)
			throws Exception {
		List<NlifeRation> riskInfoList = new ArrayList<NlifeRation>();
		List<NlifeRation> rationInfo = nlifeRationDao.queryRationInfo(map);
		List<NlifeRisk> riskInfo = nlifeRiskDao.queryNlifeRiskByParam(map);
		for (NlifeRation ration : rationInfo) {
			ArrayList<NlifeRisk> riskList = new ArrayList<NlifeRisk>();
			for(int j=0;j<riskInfo.size();j++){
				if(ration.getRationId().equals(riskInfo.get(j).getRationId())){
					riskList.add(riskInfo.get(j));
				}
			}
			ration.setNlifeRisk(riskList);
			riskInfoList.add(ration);
		}
		return riskInfoList;
	}

	@Override
	public boolean queryNlifeRiskIsExits(NlifeRisk risk) throws Exception {
		return nlifeRiskDao.queryNlifeRiskIsExits(risk);
	}

	@Override
	public boolean deleteRationByProdCode(NlifeRation ration) throws Exception {
		return nlifeRationDao.deleteRationByParam(ration);
	}

	@Override
	public List<Map<String, Object>> impNlifeProdRation(Map<String, Object> map)
			throws Exception {
		return nlifeProdDao.impNlifeProdRation(map);
	}

	@Override
	public boolean deleteAllRationByProdCode(String prodCode) throws Exception {
		return nlifeRationDao.deleteAllRationByProdCode(prodCode);
	}
	@Override
	public void toCopyAddNlifeProduct(ModelMap modelMap, String prodCode) throws Exception {
		NlifeProd tradProdInst = this.queryProdInfoById(prodCode);
		modelMap.put("product", tradProdInst);
		// 复制新增， 清除源产品号
		tradProdInst.setProdCode("");
		modelMap.put("isCopyAdd", true);
	}
	
	@Override
	public void importAllProdInfo(String sql) throws Exception{
		nlifeProdDao.insertProdInfoWithRiskCal(sql);
	}
}
